package cn.huiyunche.base.service.interfaces;

import cn.huiyunche.base.service.enums.DWaybillFeeDetailCostTypeEnum;
import cn.huiyunche.base.service.model.*;
import cn.huiyunche.base.service.vo.*;
import cn.huiyunche.base.service.vo.detail.OrderPriceInfo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * The interface D waybill service.
 *
 * @FileName: cn.huiyunche.app.service.tms.interfaces
 * @Description: 运单
 * @author: Aaron
 * @date: 2016 /11/2 上午11:12
 */
public interface DWaybillService {

    /**
     * Add by tms order d waybill.
     *
     * @param tmsOrder the tms order
     * @return the d waybill
     * @throws Exception the exception
     */
    DWaybill addByTmsOrder(TmsOrder tmsOrder) throws Exception;


    /**
     * 根据用户ID查询运单
     *
     * @param userId 用户ID
     * @param status 运单状态
     * @return d waybill
     * @throws Exception the exception
     */
    DWaybill selectDwaybillByUserId(Long userId, Integer status);

    /**
     * 根据用户ID查询运单
     *
     * @param userId 用户ID
     * @param status 运单状态
     * @return d waybill
     * @throws Exception the exception
     */
    List<DWaybill> selectDwaybillByUserId(Long userId, List<Integer> status,List<Integer> types);

    /**
     * 查询当前用户运单列表
     *
     * @param page the page
     * @return list by page
     * @throws Exception the exception
     */
    Map<String, Object> getListByPage(PageVo page,int waybillType) throws Exception;

    /**
     * 执行中 运单
     *
     * @return intransit list by page
     * @throws Exception the exception
     */
    ShowOrderVo getIntransitListByPage() throws Exception;

    /**
     * 上传交车照片
     *
     * @param id      the id
     * @param attachs the attachs
     * @param upv     integer
     * @return integer integer
     * @throws Exception the exception
     */
    Integer confirmDliver(Long id, String attachs, UserPositionVo upv) throws Exception;

    /**
     * 查询运单详情
     *
     * @param id the id
     * @return by id
     * @throws Exception the exception
     */
    DWaybillDetailVo getById(long id) throws Exception;

    /**
     * 已完成列表
     *
     * @param page the page
     * @return done by page
     * @throws Exception the exception
     */
    Map<String, Object> getDoneByPage(PageVo page) throws Exception;

    /**
     * Gets completed by tms ilineid.
     *
     * @param ilineid the ilineid
     * @return the completed by tms ilineid
     * @throws Exception the exception
     */
    DWaybill getCompletedByTmsIlineid(Long ilineid) throws Exception;

    /**
     * Compute order cost.
     * 计算运单价格信息
     *
     * @param orderCost the ordercost
     * @param isUpdate  the is update
     * @param waybillId the waybill id
     * @return the big decimal
     * @throws Exception the exception
     */
    BigDecimal computeOrderCost(String orderCost, boolean isUpdate, Long waybillId) throws Exception;

    /**
     * 队列 直接给司机派单
     *
     * @param waybill    运单ID
     * @param userPhone  司机电话
     * @param isConsumer 是否为分供方
     * @return boolean boolean
     * @throws Exception the exception
     */
// boolean dispatchDriver(Long waybillId ,String phone, boolean isConsumer);
    void dispatchDWaybill(DWaybill waybill, String userPhone, boolean isConsumer) throws Exception;

    /**
     * 人送业务的司机交车确认接口(新)，司机交车时上传交车照片、当时的位置信息
     * @param id 运单id
     * @param upv 司机上传交车照片的位置vo
     * @param attachs 司机上传交车照片的key值(json)
     * @throws Exception
     */
    int deliveryConfirm(Long id, UserPositionVo upv, String attachs) throws Exception;

    /**
     * 队列 直接给分供方司机派单
     *
     * @param orderCodes 中联订单号
     * @param user       司机信息
     * @param isConsumer the is consumer
     * @return Result<String>
     * @throws Exception the exception
     * @author hdy[Tuffy] 2016-11-20 17:08:41
     */
    Result<String> dispatchConsumerDriver(String orderCodes, SUser user, boolean isConsumer) throws Exception;

    /**
     * 查询 首页信息
     *
     * @return page info
     * @throws Exception the exception
     */
    Map<String, Object> getPageInfo() throws Exception;

    /**
     * Update waybill status.
     *
     * @param waybillId     the id
     * @param waybillStatus the value
     * @param recoveryTime  the recovery time
     * @throws Exception the exception
     */
    void updateWaybillStatusAndRecoveryTime(Long waybillId, Integer waybillStatus, Date recoveryTime) throws Exception;

    /**
     * Push order distributable info to tms.
     *
     * @param distributableInfo the distributable info
     * @return the string
     * @throws Exception the exception
     */
    String pushOrderDistributableInfoToTms(OrderDistributableInfo distributableInfo) throws Exception;

    /**
     * Push order arrival info.
     *
     * @param arrivalInfo the arrival info
     * @return the string
     * @throws Exception the exception
     */
    String pushOrderArrivalInfo(OrderArrivalInfo arrivalInfo) throws Exception;

    /**
     * Push order driver location.
     *
     * @param locationInfo the location info
     * @return the string
     * @throws Exception the exception
     */
    String pushOrderDriverLocation(OrderDriverLocationInfo locationInfo) throws Exception;

    /**
     * 判断运单 是否已经指派给司机
     *
     * @param orderLineId the order line id
     * @return boolean boolean
     * @throws Exception the exception
     */
    Boolean orderIsDispatched(Long orderLineId) throws Exception;

    /**
     * Gets by primary id.
     *
     * @param waybillId the waybill id
     * @return the by primary id
     * @throws Exception the exception
     */
    DWaybill getByPrimaryId(Long waybillId) throws Exception;

    /**
     * Gets by tms order code.
     *
     * @param orderCode the order code
     * @return the by tms order code
     * @throws Exception the exception
     */
    DWaybill getByTmsOrderCode(String orderCode) throws Exception;

    /**
     * Update selective boolean.
     *
     * @param waybill the waybill
     * @return the boolean
     */
    void updateSelective(DWaybill waybill);

    /**
     * 带伤发运－运单列表
     *
     * @param pageVo   the page vo
     * @param dWaybill the d waybill
     * @return result result
     * @throws Exception the exception
     */
    Result<Map<String, Object>> list(PageVo pageVo, DWaybill dWaybill) throws Exception;

    /**
     * 运单列表
     *
     * @param pageVo   the page vo
     * @param dWaybill the d waybill
     * @return result result
     * @throws Exception the exception
     */
    Result<Map<String, Object>> tmsList(PageVo pageVo, DWaybill dWaybill) throws Exception;

    /**
     * 退单
     *
     * @param waybillId the waybill id
     * @return result result
     * @throws Exception the exception
     */
    Result<String> cancelDWaybillWithUser(Long waybillId) throws Exception;

    /**
     * 带伤发运审核
     *
     * @param waybillId the waybill id
     * @param status    the status
     * @return result result
     * @throws Exception the exception
     */
    Result<Object> damageAudit(Long waybillId, int status) throws Exception;

    /**
     * 查询当前在途运单
     *
     * @return result result
     * @throws Exception the exception
     */
    Result<Map<String, Object>> currentWaybill() throws Exception;

    /**
     * Select by dest list.
     * 根据起始地和目的地匹配运单
     *
     * @param depaName the depa name
     * @param destName the dest name
     * @param num      the num
     * @return the list
     * @throws Exception the exception
     */
    List<SupplierCWListVo> selectByDepaAndDest(String depaName, String destName, Integer num) throws Exception;

    /**
     * Gets list by page and conditions.
     *
     * @param page          the page
     * @param waybillStatus the waybill status
     * @param paramsMap     the params map
     * @return the list by page and conditions
     * @throws Exception the exception
     */
    Map<String, Object> getListByPageAndConditions(PageVo page, List<Integer> waybillStatus, Map<String, Object> paramsMap) throws Exception;

    /**
     * Select by primary key and user id and waybill status d waybill.
     *
     * @param wid           the wid 运单主键
     * @param userId        the user id 用户主键
     * @param waybillStatus the waybill status 运单状态
     * @return the d waybill
     * @throws Exception the exception
     */
    DWaybill selectByPrimaryKeyAndUserIdAndWaybillStatus(Long wid, Long userId, Integer waybillStatus) throws Exception;

    /**
     * 分供方 出车记录
     *
     * @param page      the page
     * @param paramsMap the params map
     * @return map map
     * @throws Exception the exception
     */
    Map<String, Object> selectDriver3rdDone(PageVo page, Map<String, Object> paramsMap) throws Exception;

    /**
     * Add long.
     *
     * @param waybill the waybill
     * @return the long
     * @throws Exception the exception
     */
    Long add(DWaybill waybill) throws Exception;

    /**
     * Calc d waybill cost big decimal.
     * 计算运单费用
     *
     * @param waybillId   the waybill id
     * @param orderCostTo the order cost to
     * @param isUpdate    the is update
     * @return the big decimal
     * @throws Exception the exception
     */
    BigDecimal calcDWaybillCost(Long waybillId, OrderCostTo orderCostTo, boolean isUpdate) throws Exception;

    /**
     * 查询运单明细列表
     *
     * @param waybillId the waybill id
     * @return list list
     * @throws Exception the exception
     */
    List<DWaybillPriceDetailVo> selectPriceById(Long waybillId) throws Exception;

    /**
     * Gets list by users id.
     *
     * @param userIds the user ids
     * @return the list by users id
     * @throws Exception the exception
     */
    List<DWaybill> getListByUsersId(List<Long> userIds) throws Exception;

    /**
     * Has intransit d waybill for user boolean.
     * 判断用户是否有执行中运单
     *
     * @param userId the user id
     * @return the boolean
     * @throws Exception the exception
     */
    boolean hasIntransitDWaybillForUser(Long userId) throws Exception;

    /**
     * Select list by ids list.
     *
     * @param ids the ids
     * @return the list
     * @throws Exception the exception
     */
    List<DWaybill> selectListByIds(List<Long> ids) throws Exception;

    /**
     * Select by order line id d waybill.
     *
     * @param orderLineId the order line id
     * @return the d waybill
     * @throws Exception the exception
     */
    DWaybill selectByOrderLineId(Long orderLineId) throws Exception;

    /**
     * Select list by status list.
     *
     * @param status the status
     * @return the list
     * @throws Exception the exception
     */
    List<DWaybill> selectListByStatus(List<Integer> status) throws Exception;

    /**
     * Update is error long.
     *
     * @param id the id
     * @return the long
     * @throws Exception the exception
     */
    void updateIsError(Long id);

    /**
     * Select by example list.
     *
     * @param example the example
     * @return the list
     * @throws Exception the exception
     */
    List<DWaybill> selectByExample(DWaybillExample example) throws Exception;

    /**
     * Update is dispatch.
     *
     * @param userId        the user id
     * @param waybillId     the d waybill
     * @param dispatchDate  the dispatch date
     * @param waybillStatus the waybill status
     * @throws Exception the exception
     */
    void updateIsDispatch(Long userId, Long waybillId, Date dispatchDate, Integer waybillStatus) throws Exception;

    /**
     * 查询当前用户已交车运单列表
     *
     * @param page      the page
     * @param orderCode the order code
     * @param waybillstatus the order code
     * @param beginDate the begin date
     * @param endDate   the end date
     * @return list by page
     * @throws Exception the exception
     */
    Map<String, Object> getDeliveryListByPage(PageVo page, String orderCode,String waybillstatus, String beginDate, String endDate) throws Exception;


    /**
     * Update waybill delivery status boolean.
     *
     * @param waybillId   the waybill id
     * @param checkstatus the checkstatus
     * @param checkMark   the check mark
     * @param attachs     the attachs
     * @return boolean boolean
     * @throws Exception the exception
     * @Title: 更新订单的交车状态
     * @Description: TODO
     * @return: Result<String>
     */
    Boolean updateWaybillDeliveryStatus(Long waybillId, int checkstatus, String checkMark, String attachs) throws Exception;

    /**
     * Gets delivery photo address.
     *
     * @param id the id
     * @return delivery photo address
     * @throws Exception the exception
     * @Title: 获取交车照片的定位地址
     * @Description: TODO
     * @return: String
     */
    String getDeliveryPhotoAddress(Long id) throws Exception;


    /**
     * Gets list by code page.
     *
     * @param page      the page
     * @param orderCode the order code
     * @return list by code page
     * @throws Exception the exception
     * @Title:根据订单号查询所有待待发运和在途的订单
     * @Description: TODO
     * @return: Map<String Object>
     */
    Map<String, Object> getListByCodePage(PageVo page, String orderCode) throws Exception;


    /**
     * Update waybill check local pic boolean.
     *
     * @param waybillId the waybill id
     * @param isCheck   the is check
     * @return boolean boolean
     * @throws Exception the exception
     * @Title: 更新本地照片锁定状态
     * @Description: TODO
     * @return: Boolean
     */
    Boolean updateWaybillCheckLocalPIC(Long waybillId, Boolean isCheck) throws Exception;

    /**
     * Select Waybill By orderCode or Phone
     *
     * @param page      the page
     * @param orderCode the order code
     * @param phone     the phone
     * @return waybill list by order code and phone
     * @throws Exception the exception
     */
    Map<String, Object> getWaybillListByOrderCodeAndPhone(PageVo page, String orderCode, String phone) throws Exception;

    /**
     * Add d waybill cost.
     *
     * @param typeEnum the type enum
     * @param waybill  the waybill
     * @throws Exception the exception
     */
    Map<Integer, Object> addDWaybillCost(final DWaybillFeeDetailCostTypeEnum typeEnum, DWaybill waybill) throws Exception;

    /**
     * Update abandoned.
     *
     * @param waybillId   the waybill id
     * @param messageCode the message code
     * @param message     the message
     * @throws Exception the exception
     */
    void updateAbandoned(Long waybillId, Integer messageCode, String message) throws Exception;

    /**
     * SaveOrUpdate Attach
     *
     * @param tmsDDelivery
     * @param waybill
     * @param attachments
     * @return
     */
    String postDeliveryAttachment(TmsDDelivery tmsDDelivery, DWaybill waybill, String attachments);

    /**
     * Push order driver location.
     *
     * @param priceInfo the price info
     * @return the string
     * @throws Exception the exception
     */
    String pushOrderPrice(OrderPriceInfo priceInfo) throws Exception;

    /**
     * sava price to tms
     * @param orderCode
     *
     */
    Result<Object> pushPrice2tms(String orderCode) throws  Exception;

    /**
     *
     * @param
     * @throws Exception the exception
     * @Title: 获取第一桶油量 得到第一桶油key为firstFuelTotal; ，和剩余油量 返回 key为innageOil
     * @Description:
     * @return: map
     */
    Map<Integer,Object> getFirstBucketOil(DWaybill waybill)throws  Exception;

    /**
     * Gets quick dispatch list by code page  web.
     *
     * @param page      the page
     * @param orderCode the order code
     * @return list by code page
     * @throws Exception the exception
     * @Title:根据订单号查询所有可以急发的运单
     * @Description: TODO
     * @return: Map<String Object>
     */
    Map<String, Object> getQuickDispatchList(PageVo page, String orderCode,int waybillType, String beginDate, String endDate) throws Exception;

    /**
     * Marker orders for emergency
     * @param orderId
     * @param extraCost
     * @param specialRequired
     * @return
     * @throws Exception
     */
    void markQuickDispatch(Long orderId, String extraCost, String specialRequired, Integer waybillType) throws Exception;


    /**
     * Gets quick dispatch list by code page  app.
     *
     * @return
     * @throws Exception
     */
    void competeQuickOrderList(Long orderId) throws Exception;


    /**
     * 得到未发运的订单
     *
     * @return
     * @throws Exception
     */
     List<DWaybill> selectNoDeliveredDWaybill();

}
